/**
 * @author jouyang
 */
	QSAPI.Widget.Chart.Forex = function(mainticker,reg,language){
	this._title = "Chart";
	this.timezone = "GMT";
	this.securityType = [20]; // 8: mutural fund.
	this.precision = 4;
	this.autoTitle = true;
	this.dataUrl = {
        getTickerInfoURL :this.protocol+"qt.morningstar.com/switchservice/getids.ashx?" // get ticker information url.
    }
	//globalization parameters
    this.defaultFrequencyMenuCfg = {intraday:true,history:true,customer:true};
    this.requencyMenuCfg = {intraday:true,history:true,customer:true};// for save
    
    this.region = (reg==null?"USA":reg);
    this.lan = (language==null?"en_US":language);
    this.cur="USD";
	//corlors for line and fill.
    this.fillColors = typeof(QS_Style)!="undefined"?QS_Style.chart.fillColors:{pChart:"#c9d2dd",vChart:"#2f4880",sChart:"#d9dfeb"};
	this.colors={borderColor:null,gridColor:typeof(QS_Style)=="undefined"?"#dddddd":QS_Style.flot.grid.tickColor,lableFontColor:typeof(QS_Style)=="undefined"?"#545454":QS_Style.flot.grid.color};
	// control parameter.
    this.mainTicker = mainticker;
	this.tickerMaxNum = 7;  // the maximum compaire ticker in a chart.
    this.compairTickers =[];
	this.tickerInfos = {};
    this.mainTickerInfo = {type:"1",tenforeTicker:""} ;
    this.compairTickerInfo = [];
	this.events = {dividend:false};
	this.latestTradeDate = new Date();
	this.endDate = new Date();
    this.startDate = this.endDate;
	
    this.zoomRange = 1;
    this.chartStyle = "mountain";
    this.frequency = "minute";
    this.chartCursor = 1; // 0 Track boll; 1 Crosshair
    this.scaleType = 0; // 0 linear 1: log.
    this.yaxisAlign = "right";
    
	 //slider control parameters
	this.isShowTimeSlider=true;
    this.pChartReady = false;
    this.sliderObj = null;
    this.slider_EndDate = this.latestTradeDate; //slider end date equal to last trade date.
    this.slider_StartDate = new Date(this.slider_EndDate.getFullYear()-2,this.slider_EndDate.getMonth(),this.slider_EndDate.getDate()) ;
    this.sDates={d:null,m:null};// the start date for daily data,weekly data.monthly data.
	this.rangSize = 512;  
    this.miniChartFrequency = "d";
    this.ichartSiwtchIndicatorWin = {flag:false,oldName:"",newName:"",data:null,ulelm:null};
	    // state parameters	
	this.scrollAble = false;
	this._selectedIndicatorName = ""; // it is for indicator input parameters window.		 
    this.isDrawing = false; // if or not on drawing.
	this.lock = false; // lock
	this.showNotes =false;
    this.timeout = null;
	this.mouseWheeTimeout = null;
    this.wheelNum = 0;
	this.simpleMenu=false;  // if or not show indicator menu in SR chart right menu.
    this.chartOffset = {left:0,top:0};
	this.hasConfirmBox = (typeof(Util) != "undefined" && typeof(Util.confirm) != "undefined") ? true:false;
	this.isShowLastLabel = true;
	this.selectionMode = {pan:true,zoomIn:false,zoomOut:false};
    this.zoomStack = [];
    // options for legend window
	this.legendInfo = {OHLC:true,Volume:false,showDateRangeString:true};
    // the size parameters for chart component.
	this.chartWidth = 760;
	this.outHeight = 0;
    this.pChartHeight = 300;
    this.vChartHeight = 60;
    this.miniChartHeight = 26;
    this.yLabelWidth = 50;
    this.minW = 300;  // the minimum of width of the chart component.
    this.minH = 100;  // the minimum of height of the chart component.
    this.showGridLines  = true;
    this.iChartHeight = 80; // the height of legend is 20px and the height of mini-chart is 60px.
    // UI system configure
    this.UIConfig = {
		chartCtrl:"default",
		Chart:{
	       showTimeSlider:true
		},
		settingPanel:null,
		autoHeight:false,
		RightMenu:true,
		indicator:{},
		events:{},
		drawing:{},
		MouseWheel:true,
		ZoomIn:true
	};
	// UI Components
	this.uiComponents = {
	 	chartTypeMenu: [],        // sub menus for tab menu items.
		rightMenu:null,          // right menu for price chart.
		indexScrollPN:null,
		miniChartRightMenu:{}    // right menu for mini-chart (indicator and valuation chart). {menu: menu object,owner:the mini-chart value}
	};
	this._contains = {         
		pChartContainer:null,      // for price chart.
		mChartContainer:null,		// for silder chart
		toolContainer : null,      // for right menu.
		$settingPanel : null       // for setting Panel.
	};
	this._elements = {
		legendElm:null,
		crosshairLegendElm:null,
		crosshairLegendWin:null,
		lineXElm:null,
		lineYElm:null,
		xLabelElm:null,
		indicatorWinElm:null,
		zoomMask:null
	}
	this.iChartContainers = {};    //new chart contains 
	 // the flot object parameter.
    this.pFlot = null; // price chart
    this.mFlot = null; // slider chart.
    this.iFlots = {MACD:null,RSI:null,ROC:null,Momentum:null,Mass:null,ForceIndex:null};
	 // chart data
	this.chartData ={
		DataList:[],
		eventDataList:null,
		eventInfoList:null,
		MiniChartData: []
		};
	this.iChartData = {MACD:[],RSI:[],ROC:[],Momentum:[],WMA:[],Mass:[],ForceIndex:[]};
		// maps
	this._securityTypeMap = {"ST":1,"FE":1,"XI":10,"FO":8,"FC":1};
	this._zoomIndexMap = {1:0,2:1,13:2,3:3,14:4,4:5,5:6,6:7,7:8,8:9,9:10,10:11,11:12};
	this._frequencyIndexMap = {minute:-4,minute5:-3,minute10:-2,minute15:-1,minute30:0,d:1,w:2,m:3};
	this._frequencyTxtMap = {minute:"1 "+QSLGTXT.shortminute,minute5:"5 "+QSLGTXT.shortminute,minute10:"10 "+QSLGTXT.shortminute,
        minute15:"15 "+QSLGTXT.shortminute,minute30:"30 "+QSLGTXT.shortminute,d:QSLGTXT.daily,w:QSLGTXT.weekly,m:QSLGTXT.monthly};
	this._frequencyMap={minute:1,minute5:5,minute10:10,minute15:15,minute30:30,d:"d",w:"w",m:"m"};
	this.tabMap =  ["mountain","ohlc","candle","growth"];
	this.tabIndexMap={"mountain":0,"dot":0,"ab":0,"line":0,"ohlc":1,"hlc":1,"candle":2,"growth":3,"growth10":3};
		// data list for UI control components.
//	this.drawingData =[{val:"trendline",txt:"Trend Line"},{val:"rectangle",txt:"Rectangle"},
//		{val:"ellipse",txt:"Ellipse"},{val:"note",txt:"Note"},{val:"levelline",txt:"Level Line"},{val:"fibonacci",txt:"Fibonacci retracement levels"}];
	 // indicators parameters
    this.indicatorUI = {SMA:{title:QSLGIN.sma_t,parameter:[QSLGIN.sma_p1,QSLGIN.sma_p2,QSLGIN.sma_p3],defaultValue:[10,50,]},
		 EMA:{title:QSLGIN.ema_t,parameter:[QSLGIN.ema_p1,QSLGIN.ema_p2,QSLGIN.ema_p3],defaultValue:[10,,]},
		 BBands:{title:QSLGIN.bbands_t,parameter:[QSLGIN.bbands_p1,QSLGIN.bbands_p2],defaultValue:[20,2]},
         MACD:{title:QSLGIN.macd_t,parameter:[QSLGIN.macd_p1,QSLGIN.macd_p2,QSLGIN.macd_p3],defaultValue:[26,12,9]},
         RSI:{title:QSLGIN.rsi_t,parameter:[QSLGIN.rsi_p1],defaultValue:[14]},
         ROC:{title:QSLGIN.roc_t,parameter:[QSLGIN.roc_p1],defaultValue:[12]},
		 MAE: {title: QSLGIN.mae_t,parameter: [QSLGIN.mae_p1, QSLGIN.mae_p2],defaultValue: [14, 2]},
		 Momentum:{title:QSLGIN.momentum_t,parameter:[QSLGIN.momentum_p1],defaultValue:[2]},
		 WMA:{title:QSLGIN.wma_t,parameter: [QSLGIN.wma_p1],defaultValue: [15]}
   	};                      
    this.indicatorsData = {SMA:{show:false,num:[null,null,null],colorIndex:[0,0,0],type:0},
		SMAV:{show:false,num:null,colorIndex:0,type:0},
		EMA:{show:false,num:[null,null,null],colorIndex:[0,0,0],type:0},
		BBands:{show:false,parameter:[10,2],colorIndex:0,type:0},
		MACD:{show:false,parameter:[26,12,9],type:1,mty:1},
		RSI:{show:false,parameter:[14],type:1,mty:2},
		ROC:{show:false,parameter:[12],type:1,mty:1},
		MAE:{show:false,parameter:[14,2],type:0},
		Momentum:{show:false,parameter:[2],type:1,mty:1},
		WMA:{show:false,parameter:[15],type:0,mty:0}
 	};
	this.eventsData = [];
    this.intradayFreMenuData = [{txt:"1 "+QSLGTXT.shortminute,val:"minute",type: "ratio"},{txt:"5 "+QSLGTXT.shortminute,val:"minute5",type: "ratio"},
        {txt:"10 "+QSLGTXT.shortminute,val:"minute10",type: "ratio"},{txt:"15 "+QSLGTXT.shortminute,val:"minute15",type: "ratio"},
        {txt:"30 "+QSLGTXT.shortminute,val:"minute30",type: "ratio"}];
    this.sMinuteFreMenuData=[{txt:"5 "+QSLGTXT.shortminute,val:"minute5",type: "ratio"},{txt:"10 "+QSLGTXT.shortminute,val:"minute10",type: "ratio"},
        {txt:"15 "+QSLGTXT.shortminute,val:"minute15",type: "ratio"},{txt:"30 "+QSLGTXT.shortminute,val:"minute30",type: "ratio"},
        {txt:QSLGTXT.daily,val:"d",type: "ratio"}];
    this.lMinuteFreMenuData=[{txt:"10 "+QSLGTXT.shortminute,val:"minute10",type: "ratio"},{txt:"30 "+QSLGTXT.shortminute,val:"minute30",type: "ratio"},
        {txt:QSLGTXT.daily,val:"d",type: "ratio"},{txt:QSLGTXT.weekly,val:"w",type: "ratio"}];
    this.dailyFreMenuData=[{txt:QSLGTXT.daily,val:"d",type: "ratio"},{txt:QSLGTXT.weekly,val:"w",type: "ratio"},
        {txt:QSLGTXT.monthly,val:"m",type: "ratio"}];
    this.weeklyFreMenuData=[{txt:QSLGTXT.weekly,val:"w",type: "ratio"},{txt:QSLGTXT.monthly,val:"m",type: "ratio"}];
    this.monthlyFreMenuData = [{txt:QSLGTXT.monthly,val:"m",type: "ratio"}];
	this.zoomListData =  [{txt:"1 "+QSLGTXT.shortmonth,val:"3",type: "ratio",catekey:"zoom",selectable: false,subMenu:this.dailyFreMenuData},
		{txt:"2 "+QSLGTXT.shortmonth,val:"14",type: "ratio",catekey:"zoom",selectable: false,subMenu:this.dailyFreMenuData},
		{txt:"3 "+QSLGTXT.shortmonth,val:"4",type: "ratio",catekey:"zoom",selectable: false,subMenu:this.dailyFreMenuData},
        {txt:QSLGTXT.ytd,val:"5",type: "ratio",catekey:"zoom",selectable: false,subMenu:this.dailyFreMenuData},
		{txt:"1 "+QSLGTXT.shortyear,val:"6",type: "ratio",catekey:"zoom",selectable: false,subMenu:this.dailyFreMenuData},
		{txt:"3 "+QSLGTXT.shortyear,val:"7",type: "ratio",catekey:"zoom",selectable: false,subMenu:this.dailyFreMenuData},
		{txt:"5 "+QSLGTXT.shortyear,val:"8",type: "ratio",catekey:"zoom",selectable: false,subMenu:this.dailyFreMenuData},
		{txt:"10 "+QSLGTXT.shortyear,val:"9",type: "ratio",catekey:"zoom",selectable: false,subMenu:this.dailyFreMenuData},
		{txt:QSLGTXT.max,val:"10",type: "ratio",catekey:"zoom",selectable: false,subMenu:this.monthlyFreMenuData},
		{txt:QSLGTXT.custom,val:"11",type: "ratio"}];
	//this.frequencyListData = [{txt:QSLGTXT.daily,val:"d"},{txt:QSLGTXT.weekly,val:"w"},{txt:QSLGTXT.monthly,val:"m"}];
	this.cursorTypeListData = [{txt:QSLGTXT.trackball,val:"0",type: "ratio"},{txt:QSLGTXT.crosshair,val:"1",type: "ratio"},
	   {txt:QSLGTXT.off,val:"3",type: "ratio"}];
	this.scaleTypeListData = [{txt:QSLGTXT.linear,val:"0"},{txt: QSLGTXT.logarithmic,val:"1"}];
    this.yaxisAlignListData=[{txt: QSLGTXT.left,val:"left"},{txt:QSLGTXT.right,val:"right"}];
	this.selectionModeListData=[{txt: QSLGTXT.pan,val:"pan"},{txt: QSLGTXT.zoomin,val:"zoomin"},{txt: QSLGTXT.reset,val:"reset"}];
	this.tabList=[{txt:QSLGTXT.line,id:0,closable:false},
        {txt:QSLGTXT.bar,id:1,closable:false},{txt:QSLGTXT.candlestick,id:2,closable:false},
        {txt:QSLGTXT.growth,id:3,closable:false}];
	this.chartTypeMenuData=[[{txt:QSLGTXT.mountain,type:"ratio",val:"mountain"},
        {txt:QSLGTXT.line,type:"ratio",val:"line"},{txt:QSLGTXT.dot,type:"ratio",val:"dot"},{txt:QSLGTXT.abovebelow,type:"ratio",val:"ab"}],
        [{txt:QSLGTXT.ohlc,type:"ratio",val:"ohlc"},{txt:QSLGTXT.hlc,type:"ratio",val:"hlc"}],[],[{txt:QSLGTXT.pergrowth,type:"ratio",val:"growth"},
        {txt:QSLGTXT.tenkgrowth,type:"ratio",val:"growth10"}]];
	this.settingGroupList = [{name: QSLGTXT.display,id: 1},{name: QSLGTXT.window,id: 6}, {name: QSLGTXT.compare,id: 2,closable: false},
	 	{name: QSLGTXT.drawingandnotes,id: 3},{name: QSLGTXT.indicators,id: 4}];
	this.indicatorTabList=[{txt:QSLGTXT.popular,id:0,closable:false},
		{txt:QSLGTXT.pricetrends,id:2,closable:false},{txt:QSLGTXT.oscillator,id:3,closable:false}];
	this.indicatorPanelData=[[{txt:QSLGIN.bbands_name,val:"BBands",type: ""},{txt:QSLGIN.macd_name,val:"MACD",type: ""},
		{txt:QSLGIN.roc_name,val:"ROC",type: ""},
		{txt:QSLGIN.rsi_name,val:"RSI",type: ""},{txt: QSLGIN.sma_name,val: "SMA",type: ""}],
		[{txt:QSLGIN.bbands_name,val:"BBands",type: ""},{txt:QSLGIN.ema_name,val:"EMA",type: ""},
		 {txt:QSLGIN.mae_name,val:"MAE",type: ""},{txt:QSLGIN.macd_name,val:"MACD",type: ""},
		 {txt:QSLGIN.momentum_name,val:"Momentum",type: ""},{txt:QSLGIN.roc_name,val:"ROC",type: ""},
		 {txt: QSLGIN.sma_name,val: "SMA",type: ""},{txt: QSLGIN.wma_name,val: "WMA",type: ""}],//,{txt: "Volatility-Fast",val: "FVolatility"}
		[{txt:QSLGIN.rsi_name,val:"RSI",type: ""}]
	 	];
    this.zoomListData =  [{txt:"1 "+QSLGTXT.shortday,val:"1",type: "ratio",catekey:"zoom",selectable: false,subMenu:this.intradayFreMenuData},
        {txt:"5 "+QSLGTXT.shortday,val:"2",type: "ratio",catekey:"zoom",selectable: false,subMenu:this.intradayFreMenuData},
        {txt:"15 "+QSLGTXT.shortday,val:"13",type: "ratio",catekey:"zoom",selectable: false,subMenu:this.sMinuteFreMenuData},
        {txt:"1 "+QSLGTXT.shortmonth,val:"3",type: "ratio",catekey:"zoom",selectable: false,subMenu:this.sMinuteFreMenuData},
        {txt:"2 "+QSLGTXT.shortmonth,val:"14",type: "ratio",catekey:"zoom",selectable: false,subMenu:this.lMinuteFreMenuData},
        {txt:"3 "+QSLGTXT.shortmonth,val:"4",type: "ratio",catekey:"zoom",selectable: false,subMenu:this.lMinuteFreMenuData},
        {txt:QSLGTXT.ytd,val:"5",type: "ratio",catekey:"zoom",selectable: false,subMenu:this.dailyFreMenuData},
        {txt:"1 "+QSLGTXT.shortyear,val:"6",type: "ratio",catekey:"zoom",selectable: false,subMenu:this.dailyFreMenuData},
        {txt:"3 "+QSLGTXT.shortyear,val:"7",type: "ratio",catekey:"zoom",selectable: false,subMenu:this.dailyFreMenuData},
        {txt:"5 "+QSLGTXT.shortyear,val:"8",type: "ratio",catekey:"zoom",selectable: false,subMenu:this.dailyFreMenuData},
        {txt:"10 "+QSLGTXT.shortyear,val:"9",type: "ratio",catekey:"zoom",selectable: false,subMenu:this.dailyFreMenuData},
        {txt:QSLGTXT.max,val:"10",type: "ratio",catekey:"zoom",selectable: false,subMenu:this.monthlyFreMenuData},
        {txt:QSLGTXT.custom,val:"11",type: "ratio"}];
    this.frequencyListData = [{txt:"1 "+QSLGTXT.shortminute,val:"minute"},{txt:"5 "+QSLGTXT.shortminute,val:"minute5"},
        {txt:"10 "+QSLGTXT.shortminute,val:"minute10"},{txt:"15 "+QSLGTXT.shortminute,val:"minute15"},
        {txt:"30 "+QSLGTXT.shortminute,val:"minute30"},
        {txt:QSLGTXT.daily,val:"d"},{txt:QSLGTXT.weekly,val:"w"},{txt:QSLGTXT.monthly,val:"m"}];
    this.chartTypeListData = [{txt:QSLGTXT.mountain,val:"mountain",type: "ratio"},{txt:QSLGTXT.line,val:"line",type: "ratio"},
        {txt:QSLGTXT.dot,val:"dot",type: "ratio"},{txt:QSLGTXT.abovebelow,val:"ab",type: "ratio"},{txt:QSLGTXT.ohlc,val:"ohlc",type: "ratio"},
        {txt:QSLGTXT.hlc,val:"hlc",type: "ratio"},{txt:QSLGTXT.candlestick,val:"candle",type: "ratio"},
        {txt:QSLGTXT.pergrowth,val:"growth",type: "ratio"},{txt:QSLGTXT.tenkgrowth,val:"growth10",type: "ratio"}];
    
	//min-chart right menu list data.
    this.indicatorL2Data=[{txt:QSLGTXT.pricetrends,selectable: false,val:"mainl2-pricetrend",subMenu:this.indicatorPanelData[1]},
		{txt:QSLGTXT.oscillator,val:"mainl2-oscillator",selectable: false,subMenu:this.indicatorPanelData[2]}];
	this.ichartMenuL1Data=[[],[]]; //min-chart right menu list data. one class.
    this.miniChartRightMenuData = [{
	        txt: "<b>"+QSLGTXT.indicators+"</b>",
	        val: "mini-indicator",
	        selectable: false
	    }, {
	        txt: "&nbsp;&nbsp;"+QSLGTXT.pricetrends,
	        val: "minil1-pricetrend",
	        selectable: false,
			hasSubMenu:true
	    }, {
	        txt: "&nbsp;&nbsp;"+QSLGTXT.oscillator,
	        val: "minil1-oscillator",
	        selectable: false,
			hasSubMenu:true
	    }, {
	        type: 'separator',
	        val: "s2"
	    }, {
	        txt: QSLGTXT.edit,
	        val: "edit"
	    }];
    this.rightMenuData = [{
	        txt: QSLGTXT.charttype,
	        val: "chartType",
	        type: "",
	        selectable: false,
	        subMenu: this.chartTypeListData
	    }, {
	        txt: QSLGTXT.chartcursor,
	        val: "cursorType",
	        type: "",
	        selectable: false,
	        subMenu: this.cursorTypeListData
	    }, {
	        txt: QSLGTXT.zoom,
	        val: "zoom",
	        type: "",
	        selectable: false,
	        subMenu: this.zoomListData
	    }, {
	        txt: QSLGTXT.indicators,
	        val: "indicator",
	        selectable: false,
	        subMenu: this.indicatorL2Data
	    }];	   
};
QSAPI.Widget.Chart.Forex.prototype= $.extend({},QSAPI.Widget.Chart.Base,{
	// initilize chart interfaces.
	initUIConfig:function(config) { // init the chart UI configuration.
        $.extend(this.UIConfig,config);
        if (this.UIConfig.settingPanel != null) {
            this._contains.$settingPanel = $(this.UIConfig.settingPanel);
        }    
    },
	initStartDate: function() {
		var d = QSAPI.DataManager.Chart.dates;
        this.sDates.iMin = d[1];//new Date(y,m,d-5);
        this.sDates.sMin = d[5];//new Date(y,m-1,d-2);
        this.sDates.lMin = d[10];//new Date(y,m-3,d-10);
        this.sDates.d = d["d"];//new Date(y-2,0,1);
        this.sDates.w = d["w"];//new Date(y-20,0,1);
        this.sDates.m = d["m"];//new Date(1900,0,1);
        this.slider_StartDate = this.getSliderStartDate();   
    },
	_initConfig: function(cf)  { // init the chart's configuration
        if (cf == null || cf == "") {
            return;
        }
		if(cf.simpleMenu){  // if minichart for SR components.
			this.simpleMenu = true;
			this.rightMenuData.splice(4,1);
		}
		if (cf.chartStyle!=null){ 
			this.chartStyle = cf.chartStyle=="lines"?"mountain":cf.chartStyle;
			var hasStyle = false;
            for(var i = 0;i< this.chartTypeListData.length;i++){  //fix bug #1202 - david
                if(this.chartTypeListData[i].val == this.chartStyle){
                    hasStyle = true;
                    break;
                }
            }
            if(!hasStyle){
                this.chartStyle="mountain";
            }
		}
		if (cf.title)this._title = cf.title;
		if(cf.autoTitle!=null)this.autoTitle = cf.autoTitle;
        if (cf.mTicker != null) this.mainTicker = cf.mTicker; 
		if (cf.cTickers != null) this.compairTickers = cf.cTickers;
        if (cf.pWidth != null) this.chartWidth=cf.pWidth; 
        if (cf.pHeight != null) this.pChartHeight=cf.pHeight;
        if (cf.zRange != null) this.zoomRange = cf.zRange; 
		if (cf.startDate != null) this.startDate = RTQ_ChartUtil.convertToDate(cf.startDate);
        if (cf.endDate != null) this.endDate = RTQ_ChartUtil.convertToDate(cf.endDate);
		if (cf.region != null) this.region = cf.region;
        if (cf.lan != null) this.lan = cf.lan; 
		if (cf.cur != null) this.cur = cf.cur;
        if (cf.frequency != null) this.frequency = cf.frequency; 
        if (cf.slider_StartDate != null) this.slider_StartDate = RTQ_ChartUtil.convertToDate(cf.slider_StartDate);
        if (cf.miniChartFrequency != null) this.miniChartFrequency = cf.miniChartFrequency; 
		if (cf.events != null)$.extend(true,this.events,cf.events);
        //if (cf.showVolume != null) this.showVolume = cf.showVolume;
        if (cf.tickerInfos) this.tickerInfos = cf.tickerInfos;
        if (cf.chartCursor != null) this.chartCursor = cf.chartCursor;
		if (cf.lock!=null)this.lock = cf.lock;
		if (cf.showNotes!=null)this.showNotes = cf.showNotes;
		if(cf.yaxisAlign!=null){this.yaxisAlign=cf.yaxisAlign};
		if(cf.isShowTimeSlider!=null)this.isShowTimeSlider = cf.isShowTimeSlider;
		if(cf.scaleType)this.scaleType = cf.scaleType;
		if(cf.ticksize)this.ticksize = cf.ticksize;
		if(cf.Ticks)this.Ticks = cf.Ticks;
		if (cf.indicatorsData) { 
            for(var i in cf.indicatorsData){ // Fix bug#1199, remove the indeicators that MF can NOT support --- David 
                if(!this.indicatorsData[i]){
                    cf.indicatorsData[i] = null;
                    delete cf.indicatorsData[i];
                }
            }
			$.extend(true, this.indicatorsData, cf.indicatorsData);
		}
        if (cf.width != null) {
            this.chartWidth = (cf.width>this.minW)?cf.width:this.minW; 
        }
        if (cf.height != null) {
			if (this.UIConfig.chartCtrl == "rtqPanel") {
				this.outHeight = cf.height - 26;//window title=26 reduce window title.
			}else {
				this.outHeight = cf.height;
			}
			this._setSizeParas(this.chartWidth,this.outHeight);
        } 
		this.outObj.css({width:this.chartWidth+"px",height:this.outHeight+"px"});
        this._contains.pChartContainer.css({width:this.chartWidth+"px",height:this.pChartHeight+"px"});
		if(this._elements.zoomMask!=null)this._elements.zoomMask.css({height:this.pChartHeight+"px"});
        if(this._contains.mChartContainer!=null)this._contains.mChartContainer.css({width:this.chartWidth+"px",height:this.miniChartHeight+"px"});
    },
	saveConfig: function() {  // save the chart's configuration.
        var cf = { //title:this._title,autoTitle:this.autoTitle,lock:this.lock,showNotes:this.showNotes,isShowTimeSlider:this.isShowTimeSlider,
		mTicker:this.mainTicker,cTickers:this.compairTickers,pWidth:this.chartWidth,pHeight:this.pChartHeight,
       	mHeight:this.miniChartHeight,events:this.events,
		zRange:this.zoomRange,startDate:RTQ_ChartUtil.formatDate(this.startDate),
        endDate:RTQ_ChartUtil.formatDate(this.endDate),region:this.region,lan:this.lan,cur:this.cur,frequency:this.frequency, 
        slider_StartDate:RTQ_ChartUtil.formatDate(this.slider_StartDate),
        miniChartFrequency:this.miniChartFrequency,chartStyle:this.chartStyle,chartCursor:this.chartCursor,scaleType:this.scaleType,yaxisAlign:this.yaxisAlign,
        ticksize:this.ticksize,Ticks:this.Ticks};
		var inds = {},vals={},indD = this.indicatorsData;
		for(var o in indD){
			if(indD[o].show){ // volume: default value is true.
				if(o == "SMA"||o == "SMAV"||o == "EMA"){
					inds[o]= {show:true,num:typeof(indD[o].num)=="object"?$.extend(true,[],indD[o].num):indD[o].num};
				}else{
					inds[o]= {show:indD[o].show,parameter:$.extend(true,[],indD[o].parameter)};
				}
			}
		}
		for(var o in this.valuations){
			if(this.valuations[o].show){
				vals[o]= {show:true};
			}
		}
		cf.indicatorsData=inds;
		cf.valuations=vals;
		return cf;
	},
	// generate UI elements and UI components.
	createChartUI:function() {
		var self = this,uc = this.UIConfig, el = this._elements, cons = this._contains,uiComps = this.uiComponents;
        this.outObj.html(""); // clear html.
		var cc = $('<div class="rtc-chart-container rtc-price-chart"></div>').appendTo(this.outObj); // create price chart container.
		el.legendElm = $('<div class="rtc-legend-txt"></div>').appendTo(cc);  // add price chart legend
		cons.pChartContainer = $('<div class="rtc-chart rtc-chart-main"></div>').appendTo(cc);
		if(uc.ZoomIn){
            el.zoomMask = $('<div style="display:none" class="chart-zoom-mask"></div>').appendTo(cons.pChartContainer);
        }   
		// create crosshair hover window.
		el.crosshairLegendWin = $('<div class="rtc-legend-win" style="display:none;">'+
			'<div class="rtc-legend-win-wrap"></div></div>').appendTo(cons.pChartContainer);
		el.crosshairLegendElm = el.crosshairLegendWin.find(".rtc-legend-win-wrap");
        el.lineXElm = $('<div class="rtc-line-x"><span></span></div>').appendTo(cons.pChartContainer);
		el.lineYElm = $('<div class="rtc-line-y"></div>').appendTo(cons.pChartContainer);
		el.xLabelElm = el.lineXElm.find(":first-child");
		var mCon = $('<div class="rtc-chart-container"></div>').appendTo(this.outObj);
		cons.mChartContainer = $('<div class="rtc-chart"></div>').appendTo(mCon); 	  
        if(typeof(this.afterCreateUI)=="function"){
            this.afterCreateUI();
        }
    },
	_setSizeParas: function(wd,hg){
		this.chartWidth = wd;
		this.outHeight = hg;
        var ih = this.getIChartsHeight();
        var h = hg-ih-25;  // slider chart :30px, subject chart legend height:25px.
        if (this.isShowTimeSlider) {
			h = h - 30;
		}
        if (this.UIConfig.chartCtrl == "rtqPanel") {
             h-=30;  // tab menu height.
        }
        var hh = h>this.minH?h:this.minH;
        this.pChartHeight = hh;
	},
	initComponent:function() { // init component state.
		var self = this;
        this._attachUIEvents();
        this._initUiComponentsStatus(); // init the status of UI controls.
        this.chartData.DataList = this.chartData.eventDataList = null;
        for(var o in this.iChartData){
			this.iChartData[o] = [];
		}
        this.initStartDate();
		if (typeof(this.setTitle)=="function") {
	        var t = this._getClientTicker(this.mainTicker);//this.tickerInfos[this.mainTicker]["ticker"];
	        this.setTitle(this._title,t);
	    }
        this.changeRange(this.zoomRange);
        setTimeout(function() {self.getSilderChartData();},200);
    },
	_initUiComponentsStatus: function() {  // initilize the status of UI  components.
	 	var el = this._elements, uiComps = this.uiComponents;
        if (uiComps.rightMenu != null) {
            if(this.events.dividend) uiComps.rightMenu.changeUIState("dividend",null,true);
			uiComps.rightMenu.changeUIState(this.chartStyle,null,true);
			uiComps.rightMenu.changeUIState(this.chartCursor,null,true);
        }
        if(this.chartCursor != "1" && this.chartCursor != 1) {
            el.lineXElm.hide();
            el.lineYElm.hide();
        }
		if(this.yaxisAlign=="right"){
			el.xLabelElm.css({right:0,left:""});
		}else{
			el.xLabelElm.css({left:0,right:""});
		}
		for(var i = 0;i<this.chartTypeMenuData.length;i++){
			if(uiComps.chartTypeMenu[i]!=null && this.tabIndexMap[this.chartStyle]==i){  // select tab is growth.
				uiComps.chartTypeMenu[i].changeUIState(this.chartStyle,null,true);
			}
		}
        for (var o in this.indicatorsData) {             // change indicator menu state.
            if (this.indicatorsData.hasOwnProperty(o) ) {
                 if (this.indicatorsData[o].show) {
                      if (this.UIConfig.RightMenu) {
                          if (o == "Volume") {
                              this.changeRightMenuClass(2, o, this.showVolume);
                              continue;
                          }
                          this.changeRightMenuClass(2, o, true);
                      }
                 }
            }
        }
    },
	_attachUIEvents: function () {  // bind events to price chart and volume chart legends.
		var el = this._elements, self = this, cons = this._contains;
		el.legendElm.unbind().bind("mouseover.rtqChart",function(e){  // mouse over price chart legend.
			var t = $(e.target);
			if (e.target.tagName.toUpperCase() == "SPAN" || t.hasClass("rtc-legend")) {
				var elm = t.closest(".rtc-legend");
				if (elm.attr("name") != "MReturnIndex") 
					elm.find(".rtc-legend-remove").removeClass("rtc-remove-hide"); // not dividend effect chart legend
			}
		}).bind("mouseout.rtqChart",function(e){                   // mouse out legend.
			el.legendElm.find(".rtc-legend-remove").toggleClass("rtc-remove-hide",true);
		}).bind("click.rtqChart",function(e){
			var t = $(e.target), ty = t.data("type");
			if (e.target.tagName.toUpperCase() == "SPAN" && t.hasClass("rtc-legend-remove")) {
				var elm = $(e.target).closest(".rtc-legend");
				self.legendOnClick(elm);
			}else if(ty=="ct"){  // click the compair ticker. switch it to main ticker.
				el.legendElm.find(".rtc-legend-bold").removeClass("rtc-legend-bold");
				t.addClass("rtc-legend-bold");
				var pm = t.parent(),mT = pm.attr("name");
				if(pm&&mT){
					var mt = self.mainTicker;
					for(var i = 0; i<self.compairTickers.length;i++){
						if(self.compairTickers[i]==mT){
							self.compairTickers[i] = self.mainTicker;
							self.mainTicker = "";
							self.acceptTicker(self.tickerInfos[mT]);
							break;
						}
					}
				}
			}
		});
		this.attachMouseScoll();     
		this.attachZoomIn();         
    },
	getPChartData:function(successCallback){
		var self = this;
		this.pChartReady = false; // request chart data for price  chart.
		var option = [], ty = this.compairTickers.length > 0 ? "return":"price"; 
		if(this.chartStyle == "growth"||this.chartStyle=="growth10") ty = "return";
		if(this.chartStyle == "growth10"){
			ty+="_k";
		}
		var ls = {symbol:this.mainTicker,datapoints:{p:ty,indicators:[]}};
        if(this.chartStyle == "postTax"){
            ls = {symbol:this.mainTicker,datapoints:{postTax:"return",indicators:[]}};
        }
		if(this._frequencyIndexMap[this.frequency]>0){  // daiy, weekly, monthly.
			if(this.events.dividend ){
				ls.datapoints.ds= {isD: this.events.dividend };
			}
		}
		if(this.chartStyle == "growth10"){  // dividend effect chart.
			option.push(ls);
			if(this.chartStyle == "growth10"){
				if(this.compairTickers.length){
					for(var j = 0; j< this.compairTickers.length;j++){
						option.push({symbol:this.compairTickers[j],datapoints:{p:ty}});
					}
				}
			}
		}else{
			for(var o in this.indicatorsData){  // add overlayer chart data option.
				if(this.indicatorsData[o].type == 0){ 
					if(o=="EMA"||o=="SMA"){
						for(var i=0;i<this.indicatorsData[o].num.length;i++){
							if(this.indicatorsData[o].num[i]!=null){
								ls.datapoints.indicators.push({name:o,p:[this.indicatorsData[o].num[i]],vtype:ty});
							}
						}
					}else if(this.indicatorsData[o].show){  
						ls.datapoints.indicators.push({name:o,p:this.indicatorsData[o].parameter,vtype:ty});
					}
				}
			}
			option.push(ls);		
			if(this.compairTickers.length){
				for(var j = 0; j< this.compairTickers.length;j++){
					option.push({symbol:this.compairTickers[j],datapoints:{p:ty}});
				}
			}
		}	
		var stIndx = RTQ_ChartUtil.toDateIndex(this.startDate);
   		var endIndx = RTQ_ChartUtil.toDateIndex(this.endDate);
		if(this.UIConfig.chartCtrl=="rtqPanel"&&(typeof(this.showLoading) == 'function')) {// show loading img
			this.showLoading();
		}
		if(this._frequencyIndexMap[this.frequency]>0){  // historical
			QSAPI.DataManager.Chart.getHistoricalData(option,this._frequencyMap[this.frequency],stIndx,endIndx,function(data){
			self.pChartDataReady(data,successCallback)});
		}else{
			QSAPI.DataManager.Chart.getIntradayData(option,this._frequencyMap[this.frequency],stIndx,endIndx,function(data){
            self.pChartDataReady(data,successCallback)});
		}
	},
	getSilderChartData: function(){
		var dx=5, m = this.miniChartFrequency, startIndex=null, endIndex = null, self = this;
		if(this.miniChartFrequency == "minute"){
			dx = 1, m = "d";
			startIndex = RTQ_ChartUtil.toDateIndex(this.sDates.lMin), endIndex = RTQ_ChartUtil.toDateIndex(this.slider_EndDate);
		}
		var option = [{symbol:this.mainTicker,dx:dx,datapoints: {p:"price"}}];
		QSAPI.DataManager.Chart.getHistoricalData(option,m,startIndex,endIndex,function(data){
			self.sliderChartDataReady(data)		
		});
	},
	getIChartData: function(sName){
		var cd = this.chartData,self = this;
		if(this.iChartData[sName]||sName=="FairValue"||sName == "MReturnIndex"){
			var option;
			var stIndx = RTQ_ChartUtil.toDateIndex(this.startDate);
       		var endIndx = RTQ_ChartUtil.toDateIndex(this.endDate);
			if(this.indicatorsData[sName]||sName=="RDividend"||sName=="DYield"){
				var par = sName=="RDividend"||sName=="DYield"?[]:this.indicatorsData[sName].parameter;
				option =  [{symbol:this.mainTicker,datapoints: {indicators: [{name: sName,p: par,vtype:"price"}]}}];
				if (this._frequencyIndexMap[this.frequency] > 0) { // historical
                    QSAPI.DataManager.Chart.getHistoricalData(option, this._frequencyMap[this.frequency], stIndx, endIndx, function(data){
                        self.iChartDataReady(data);
                    });
                } else { //intrady
                    if (this.zoomRange < 3) {
                        option[0].days = this.zoomRange == 1 ? 1 : 5;
                    }
                    QSAPI.DataManager.Chart.getIntradayData(option,this._frequencyMap[this.frequency],stIndx,endIndx,function(data){
                        self.iChartDataReady(data);
                    });
                }
			}
		}
	},
	drawPChart:function() { // draw price chart.
		var cd = this.chartData, self = this, cons = this._contains, el = this._elements;
        if (cd.DataList == null || cd.DataList.length < 1) { 
            return;
        }
        this.mouseOutChart();
        var dlist = cd.DataList[0].data,dlen = dlist?dlist.length:0;
        var isSameDay = false;
        if(this._frequencyIndexMap[this.frequency]<=0&&dlen>0)isSameDay = RTQ_ChartUtil.compareDateByday(new Date(dlist[dlen-1][dlist[dlen-1].length-1]), new Date(dlist[0][dlist[0].length-1]));
        if (this.zoomRange > 2&&!isSameDay) { // historical
            this.ticksize = null, this.Ticks = this.getTicks(cd.DataList[0].data,this.frequency);
            this._isIntradayTimSyle = false;
        } else {
           this.Ticks = null;
           if(this.zoomRange==1||isSameDay) this._isIntradayTimSyle = true;
           else this._isIntradayTimSyle = false;
           if(this.zoomInMode==1){
               this.ticksize = Math.round(dlen/4);
           }else{
               this.ticksize = (this.zoomRange==1||(isSameDay&&this.zoomRange==11))?60/this._frequencyMap[this.frequency]:Math.ceil(cd.DataList[0].data.length/(this.zoomRange==0?3:5));
           }
           this.xLabelAlign = (this.zoomRange==1||(isSameDay&&this.zoomRange==11)?"left":"center");
        }
        if (this.pFlot == null) { 
            this.pFlot = new mstar.flot(cons.pChartContainer,this.getChartOption("priceLine"));
			this.pFlot.setOption({imageHighlight:this.chartCursor==0});
            cons.pChartContainer.unbind("plothover").bind("plothover", function(event, pos, item){
									 		self.buildLegend(item,pos,false,false);
										});
            cons.pChartContainer.unbind("mouseout").bind("mouseout", function(e) { 
               var t = e.relatedTarget ? e.relatedTarget.nodeName.toLowerCase() : "";
			   if(Util.contains(cons.pChartContainer[0],e.relatedTarget)) return false;
			   else {
			   		if(self.timeout)clearTimeout(self.timeout);
			   		self.chartMouseOut();
			   }
			} );
            cons.pChartContainer.unbind("mouseover").bind("mouseover", function() {
				if(self.timeout)clearTimeout(self.timeout);
				self.chartOffset = cons.pChartContainer.offset();
				el.lineXElm.css({width:self.chartWidth});
				el.lineYElm.css({height:cons.pChartContainer.height()});
			} );
			this.pFlot.drawObj.beforeRemoveDrawing= function(drawingType,point){  // remove one drawing points from chart data manager.
				QSAPI.DataManager.Chart.quoteDataMap[self.mainTicker].removeDrawing(drawingType,point);
			};
			this.pFlot.drawObj.onDrawingUpdated = function(drawingType,point){
				QSAPI.DataManager.Chart.quoteDataMap[self.mainTicker].updateDrawing(drawingType,point);
			};
			cons.pChartContainer.unbind("drawEnd").bind("drawEnd",function(e,drawType){ 
				var drawPoint = self.pFlot.drawObj.getLastDrawing(drawType);
				if(drawPoint!=null) QSAPI.DataManager.Chart.quoteDataMap[self.mainTicker].saveLastDrawing(drawType,drawPoint);
				self.isDrawing = false;
				if(self.chartCursor==1){
					el.crosshairLegendWin.show();
				}
                if(typeof(self.afterDrawEnd)== "function"){
                    self.afterDrawEnd(drawType);
                }
			});
        }
        var data = [];
        var w = 1, cloIndx;  // w is line width.
        for (var i = 0; i < cd.DataList.length; i++) { 
            w = i == 0?2:1;
			cloIndx = cd.DataList[i].colorIndex == null ?i:cd.DataList[i].colorIndex;
			var sty = "line";
            if (i == 0) {   // subject ticker.
            	var sy = this.chartStyle;
				startPos = cd.DataList[i].startPos;
				sty = sy == "mountain"||sy=="growth"||sy=="growth10"||sy=="dEffect"||sy=="postTax"?"mountain":this.chartStyle;
            }
			data.push(this.getChartData(cd.DataList[i].data,sty,1,cloIndx,w));
        }
        if (this.zoomRange > 2&&this._frequencyIndexMap[this.frequency]>0 &&
			(this.events.dividend || this.events.splits||this.events.earnings) &&
			 cd.eventDataList != null && cd.eventDataList.length > 0) {  //historical data;
             data.push(this.getChartData(cd.eventDataList,"img",1,null)); 
        }
		var cs = this.chartStyle;
		var scal = (this.scaleType == "1" && (this.compairTickers.length > 0||cs=="growth"||cs=="dEffect"))?0: parseInt(this.scaleType,10);
		var drawingAble = true,unit = cs=="growth10"?"k":"";;
		if(cs=="mountain"||cs=="line"||cs=="dot"||cs=="ab"||cs=="growth"||cs=="growth10"||cs=="dEffect"){
			var ct = (cs=="growth"||cs=="growth10"||cs=="dEffect")?"mountain":cs;
			this.pFlot.setOption({xaxis:{tickSize:this.ticksize,ticks:this.Ticks,textAlign:this.xLabelAlign},
				lines:{lineType:ct},yaxis:{scaleType:scal},drawingAble:drawingAble});
		}else if(this.chartStyle=="ohlc"||this.chartStyle=="hlc"){
			 this.pFlot.setOption({xaxis:{tickSize:this.ticksize,ticks:this.Ticks,textAlign:this.xLabelAlign},
			 	OLHC:{olhcType:this.chartStyle},yaxis:{scaleType:scal},drawingAble:drawingAble});
		}else{
			 this.pFlot.setOption({xaxis:{tickSize:this.ticksize,ticks:this.Ticks,textAlign:this.xLabelAlign},
			 	yaxis:{scaleType:scal},drawingAble:drawingAble});
		}   
		this.pFlot.setOption({yaxis:{align:this.yaxisAlign,unit:unit},otherInfo:{ticker:this.mainTicker}});
        this.pFlot.init(data);
		if(data&&data.length&&data[0].data.length){
			var tyy = "price";
			if(this.compairTickers.length) tyy="return";
			else if(cs=="growth"||cs=="dEffect") tyy ="return";
			if(cs=="growth10")tyy="return10";
			this.pFlot.setChartTypeForDrawings(tyy,startPos); // tell drawing object whar chart type is in.
			this._loadDrawings(data[0].data,function(points){
				if(self.pFlot.drawObj){
					self.pFlot.drawObj.setDrawings(points);
					self.pFlot._triggerRedrawOverlay();// redraw the overlay
				}
				
			});
		}		
        this.pChartReady = true;  
    },
	changeFrequencyStyle: function(num) {
        var uiComps = this.uiComponents, el = this._elements, f, mf ;
        if (num == 1 || num == 2||num==0) {  // 0: 3 days
            f = "minute";
            if (this._frequencyIndexMap[this.frequency] > 0) {
                this.frequency = f;
            }
            mf="minute"; 
        } else { 
            f = this.calculateFrequency(this.startDate); 
            mf = f;
        }
        this.changeFrequency(f);
        if (uiComps.rightMenu != null) { 
            uiComps.rightMenu.changeUIState(num,"zoom",true);
        }
        if (this._frequencyIndexMap[mf] > 0 && mf != this.miniChartFrequency) {  //slider chart view changed
            this.miniChartFrequency = mf;
            this.getSilderChartData();
        }else if(this._frequencyIndexMap[mf] <= 0&& this.miniChartFrequency != "minute"){//slider chart view changed
            this.miniChartFrequency = "minute";
            this.getSilderChartData();
        }else{
            this.setSliderHandleValues();
        }
    },
	changeFrequency: function(f) {
        if (this._frequencyIndexMap[f] > this._frequencyIndexMap[this.frequency]) {
            this.frequency = f;
        }else if ((this.zoomRange == 13||this.zoomRange == 3)&&this._frequencyIndexMap[this.frequency] > 1 ) {// 15 days or 1 mth
            this.frequency = "d";
        }else if((this.zoomRange == 14||this.zoomRange == 4)&&this._frequencyIndexMap[this.frequency] > 2){// 2 mth or 3 mth
            this.frequency = "w";
        }else if (this.zoomRange==11){
            if((f == "minute" && this._frequencyIndexMap[this.frequency] >= this._frequencyIndexMap["d"]))this.frequency = f;
            else if(f == "minute5"&&this._frequencyIndexMap[this.frequency] >= this._frequencyIndexMap["w"])this.frequency = "d";
            else if (f == "minute10"&&this._frequencyIndexMap[this.frequency] >= this._frequencyIndexMap["m"])this.frequency = "w";
            else if(f == "minute10"&&this.frequency == "minute15")this.frequency = "minute30";  // not contains 15 minute frequency.
        }
        if (this.UIConfig.pCtrl1 == null || !this.UIConfig.pCtrl1.showFrequency) {
            this.frequency = f; 
        }// if can't exist frequency control element
        this.bindFrequencyMenu(this.frequency);
    },
	_getFrequencyList:function(type){  //
		var range = [0,7],max = 7,min =0, freqList = [];
		if(type=="i") range =[0,4];  // intraday frequencies
		else if(type=="sm") range =[1,5];  //
		else if(type=="lm") range =[2,6];
		else if(type=="d") range =[5,7];
		else if(type=="w") range =[6,7];
		else if(type=="m") range =[7,7];
		if(this.requencyMenuCfg.intraday&&!this.requencyMenuCfg.history) max = 4;
		else if(!this.requencyMenuCfg.intraday&&this.requencyMenuCfg.history) min = 5;
		for(var i=0;i<this.frequencyListData.length;i++){
			if(i<range[0]||i>range[1]||i<min||i>max) continue;
			freqList.push(this.frequencyListData[i]);
		}
		return freqList;
	},
	bindFrequencyMenu: function(f) {
		var st = this._frequencyIndexMap[f],uiComp = this.uiComponents, el = this._elements;
		var frequencyData = [];
		if(st!= this.selectFreIndex){
			if(st <= -4||this.zoomRange<3) {
				frequencyData = this._getFrequencyList("i");
	        }else if(st<=-3){ 
				frequencyData = this._getFrequencyList("sm");			// 5, 10,15,30,d
			}else if(st<=0){ 
				frequencyData = this._getFrequencyList("lm"); // 10,30,d
			}else if(st==1){
				frequencyData = this._getFrequencyList("d");
	        } else if(st==2){
				frequencyData = this._getFrequencyList("w");
			}else if(st==3){
				frequencyData = this._getFrequencyList("m");
			}
			this.selectFreIndex = st;
		}
		if(typeof(this.afterFrequencyDataChanged)=="function"&&frequencyData.length){
			this.afterFrequencyDataChanged(frequencyData);
		}
		if(typeof(this.afterFrequencyChanged)=="function"){
			this.afterFrequencyChanged(this.frequency);
		}
		if (uiComp.rightMenu != null) {
			uiComp.rightMenu.changeUIState(this.frequency,this.zoomRange,true);
		}
    },
	calculateFrequency: function(startDate) {   // calculate frequency by range and start Date.
	    var f = "minute", range = this._calFrequencyByRange(), s = this.startDate;
       if(s >=this.sDates.iMin || (range <= 5 && this.startDate >=this.sDates.lMin)) f="minute";
       else if (s >= this.sDates.sMin || (range < 30&&s >= this.sDates.lMin)) f="minute5";
       else if (s >= this.sDates.lMin)f="minute10"
       else if (s >= this.sDates.d) f = "d";
       else if (s >= this.sDates.w) f = "w"; 
       else f= "m" ;
       return f;
    },
    _calFrequencyByRange: function(){
        var days  = (this.endDate.getTime()-this.startDate.getTime())/86400000;
        return days;
    },
	_upMiniFrequency: function() {  
        var f;
	    if (this.miniChartFrequency == "d") {
            f = "m";
        } else {
            f ="m";
        }
        return f;
    },
	drawSliderChart:function() {
		var  cons = this._contains;
		if(cons.mChartContainer==null)return false;
        if(this.mFlot == null) {
            this.mFlot = new mstar.flot(cons.mChartContainer,this.getChartOption("miniChart"));    
        }
        var ticks = this.chartData.MiniChartData.length?this.getTicks(this.chartData.MiniChartData[0],"d"):[];
		this.mFlot.setOption({xaxis:{tickSize:null,ticks:ticks}});
        this.mFlot.init(this.chartData.MiniChartData);
    },
	exportDataToExcel:function(){
		if(this.mainTicker==""||this.mainTicker==null)return;
		var symbols = [this.mainTicker],st = RTQ_ChartUtil.formatDate(this.startDate),ed = RTQ_ChartUtil.formatDate(this.endDate);
		if(this.compairTickers.length)symbols = symbols.concat(this.compairTickers);
        if(this._frequencyIndexMap[this.frequency]<1){ // intraday data
            ty = 3;
        }else {  // historical data.
            ty = 5;
        }
		QSAPI.DataManager.Chart.exportDataToExcel(symbols,ty,st,ed,this._frequencyMap[this.frequency],null);
	},
	fileMenuCallback:function(val){  // handler the file menu in windows click event.
		if(val=="export"){  // export data to excel.
			this.exportDataToExcel();
		}
	},
    refreshIntradayChart: function(type){
        if(this.zoomRange < 3||(this.frequency=="d"&&RTQ_ChartUtil.compareDateByday(this.endDate,this.latestTradeDate))){// daily or intrady chart.
            if (type == "p") {// refresh price chart
                this.getPChartData();
                for(var o in this.indicatorsData){
                    if(this.indicatorsData[o].type == 1 && this.indicatorsData[o].show){  // refresh indicator chart.
                        this.getIChartData(o);
                    }
                }
            }else if(type == "v"){ //refresh volume chart
                this.getVChartData();
            }
        }
    },
	refreshLastTradeDate:function(){
		
	}
});
